// pages/paihangbang/paihangbang.js
import { Rank } from './rank-model.js';
var rank = new Rank();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected: true,
    selected1: false,
    moreLoading: false,
    loadingHidden: false,
    pageNumber: 1, //当前页数
    totalPage: 5, // 总页数
  },

  selected: function (e) {
    this.setData({
      selected1: false,
      selected: true
    })
  },
  selected1: function (e) {
    this.setData({
      selected: false,
      selected1: true
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.data.id = id;
    if (id == 2) {
      this.setData({
        selected: false,
        selected1: true
      })
    }
    this._loadData();
  },

  _loadData: function () {
    var that = this;

    rank.getFeedData((res) => {
      that.setData({
        feedData: res.data,
        loadingHidden: true
      })
    })
    rank.getCollectData((res) => {
      that.setData({
        collectData: res.data
      })
    })
  },

  petsInfoTap: function (e) {
    var id = rank.getDataSet(e, 'id');
    wx.navigateTo({
      url: '../pets-info/pets-info?id=' + id,
    })
  },

  onReachBottom: function (e) {
    var self = this;
    var pageNumber = self.data.pageNumber + 1;

    if (pageNumber <= self.data.totalPage) {
      self.setData({
        pageNumber: pageNumber,
        moreLoading: true
      })
      return;
      // 请求后台，获取下一页的数据。
      wx.request({
        url: '',
        data: {
          pageNumber: pageNumber,
        },
        success: function (res) {
          wx.hideLoading()
          self.setData({
            showlist: self.data.showlist.concat(res.data.list)
          })
        },
        fail: function (res) {
          wx.hideLoading()
        }
      })
    }
  },

})